//2018.1.16
var ishare=importShare();

//-------------------------------------------------------自定义分享内容
(function() {
    ishare.wxId ='';//微信 appid
	var hrefs=window.location.href.split('?');
	ishare.url=hrefs[0].substr(0, hrefs[0].lastIndexOf('/')+1);
	ishare.content={
		link:ishare.url,
		image:ishare.url+'images/share.jpg?v='+Math.random(),
		title:"OPPO A7预约名片生成器",
		friend:'OPPO A7预约开启，快来制作你的专属预约名片！',
		timeline:'OPPO A7预约名片生成器'
	};
	console.log(ishare.content);
	if(os.weixin){
		ishare.from=icom.getQueryString('from');
		ishare.from=ishare.from||'friend';
		ishare.from= ishare.from=='groupmessage' || ishare.from=='singlemessage' ? 'friend' : ishare.from;
		console.log('微信分享来源：'+ishare.from);
		ishare.wxSign();
	}
}());

function importShare(){
	var imonitor=window.imonitor||{};
	var share={};
	share.wxSigned=false;
	
	//-------------------------------------------------------微信SDK验证
	share.wxSign=function(){
		 $.get("https://scrm.h5-x.com/api/jssdk/sign", { appid: share.wxId, url: location.href }, function (data) {
			wx.config({
				debug: false,
				appId: data.appid,
				timestamp: data.timestamp,
				nonceStr: data.noncestr,
				signature: data.signature,
				jsApiList: [
					'checkJsApi',
					'onMenuShareTimeline',
					'onMenuShareAppMessage',
					'onMenuShareQQ',
					'onMenuShareWeibo',
					'hideMenuItems',
					'showMenuItems',
					'hideAllNonBaseMenuItem',
					'showAllNonBaseMenuItem',
					'translateVoice',
					'startRecord',
					'stopRecord',
					'onRecordEnd',
					'playVoice',
					'pauseVoice',
					'stopVoice',
					'uploadVoice',
					'downloadVoice',
					'chooseImage',
					'previewImage',
					'uploadImage',
					'downloadImage',
					'getNetworkType',
					'openLocation',
					'getLocation',
					'hideOptionMenu',
					'showOptionMenu',
					'closeWindow',
					'scanQRCode',
					'chooseWXPay',
					'openProductSpecificView',
					'addCard',
					'chooseCard',
					'openCard'
				]
			});//end wx.config
			share.wxSigned=true;//通过微信新SDK验证
			wx.ready(function(){
				//wx.showOptionMenu();//用微信“扫一扫”打开，optionMenu是off状态，默认开启
				share.wxShare();
			});//end wx.ready
		},'json');//end ajax
	}//end func
	
	//-------------------------------------------------------微信分享函数
	share.wxShare=function(){
		if(share.wxSigned){
			var sharelink = share.content.link;
	        if (localStorage.openid) {
	            sharelink = sharelink + (sharelink.indexOf('?') > 0 ? '&' : '?') + 'from_openid=' + localStorage.openid;
	        }
	        wx.onMenuShareTimeline({
	            title: share.content.timeline, // 分享标题
	            link: sharelink, // 分享链接
	            imgUrl: share.content.image, // 分享图标
	            success: function () {
	                // 用户确认分享后执行的回调函数
	                if (imonitor.add) imonitor.add({ label: '分享到朋友圈' });
	                if (share.wxShareSuccess) share.wxShareSuccess();
	            },
	            cancel: function () {
	                // 用户取消分享后执行的回调函数
	                if (share.wxShareCancel) share.wxShareCancel();
	            }
	        });
	        wx.onMenuShareAppMessage({
	            title: share.content.title, // 分享标题
	            desc: share.content.friend, // 分享描述
	            link: sharelink, // 分享链接
	            imgUrl: share.content.image, // 分享图标
	            type: 'link', // 分享类型,music、video或link，不填默认为link
	            dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
	            success: function () {
	                // 用户确认分享后执行的回调函数
	                if (imonitor.add) imonitor.add({ label: '分享给朋友' });
	                if (share.wxShareSuccess) share.wxShareSuccess();
	            },
	            cancel: function () {
	                // 用户取消分享后执行的回调函数
	                if (share.wxShareCancel) share.wxShareCancel();
	            }
	        });
		}//end if
		else setTimeout(share.wxShare,250);
	}//end func
	

	
	
	
	share.reset=function(opts){
		if(opts){
			if(opts.link) share.content.link=opts.link;
			if(opts.image) share.content.image=opts.image+'?v='+Math.random();
			if(opts.title) share.content.title=opts.title;
			if(opts.friend) share.content.friend=opts.friend;
			if(opts.timeline) share.content.timeline=opts.timeline;
			if(os.weixin) wx.ready(function(){
				share.wxShare();
			});//end wx.ready
			else share.wbShare({ obj:share.shareBtn, url: share.content.link, text: share.content.timeline, image: share.content.image });
		}//end if
	}//end func
	
	share.hideMenu=function(menuList){
		wx.ready(function(){
			menuList=menuList||[ "menuItem:copyUrl"];
			wx.hideMenuItems({
			    menuList: [ "menuItem:copyUrl"] // 要隐藏的菜单项
			});
		});//end wx.ready
	}//end func
	
	
	
	return share;
}//end import